const MongoClient = require('mongodb').MongoClient;

const url = 'mongodb://localhost:27017';

const path = require("path");

const log = require(path.resolve(__dirname, '../../../tool/log/log'));

class DB{
    constructor(dbname = ''){
       this.dbname = dbname; 
    }
    qy(opt = '', collection = '', ag = [], cb = () => {}){
        const url = 'mongodb://127.0.0.1:27017';
        const dbName = this.dbname;
        MongoClient.connect(url, function(err, client) {
             if(!err){
                 const db = client.db(dbName);
                 const conn = db.collection(collection); 
                 cb(conn[opt](...ag));
             } else {
                 log.error.error('mongo==>dbname '+dbName+ ' collection '+collection);
                 log.error.error(err);
             }
        })
    }
}

module.exports = DB;
